﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities;
using Wicresoft.Platform.Workflows.Mobile.Tasks;

namespace Wicresoft.Platform.Workflows.Mobile.Activities
{

    public sealed class BookmarkActivity<T> : NativeActivity<Wicresoft_Platform_Processes_Mobile>
        where T : IResumeTask, new()
    {
        private T task = new T();

        protected override bool CanInduceIdle
        {
            get
            {
                return true;
            }
        }

        protected override void Execute(NativeActivityContext context)
        {
            context.CreateBookmark(task.State.ToString(), BookmarkCallback);
        }

        private void BookmarkCallback(NativeActivityContext context, Bookmark bookmark, object value)
        {
            var wppMobile = task.Resume(context, bookmark, value as Wicresoft_Platform_Processes_Mobile);
            this.Result.Set(context, wppMobile);
        }
    }
}
